<?php  
// 建立客户端的socet连接  
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);  
$connection = @socket_connect($socket, '115.29.42.220', 10008);    //连接服务器端socket

//$data = array("worker"=>"Room","action"=>"sitDown","runData"=>array("userID"=>4,'roomID'=>20,'seat'=>3,'jetton'=>2000));
//$data = array("worker"=>"Login","action"=>"login","runData"=>array("loginName"=>'machao','password'=>"111111"));
//$data = array("worker"=>"Room","action"=>"enterRoom","runData"=>array("userID"=>3,'roomID'=>5,'jetton'=>1000));
$data = array("worker"=>"Game","action"=>"getGameInfo","runData"=>array('userID'=>4,"roomID"=>20));
//$data = array("worker"=>"Game","action"=>"qjoin","runData"=>array("userID"=>123));
//echo json_encode($data);exit; 
if(!$connection){
	echo "can not connect";exit;
}
while(true){
	if (!socket_write($socket,(json_encode($data))."\n")) {
		echo "Write failed\n";
	}
	while ($buffer = socket_read($socket, 1024, PHP_NORMAL_READ)) {
		echo "response from server was:" . $buffer . "\n";
		//socket_write($socket,(json_encode($data))."\n");
	}
	sleep(10);
}
//add test git
/* 
while ($buffer = @socket_read($socket, 1024, PHP_NORMAL_READ)) {  
    //服务端告诉客户端，自己的状态  
    if (preg_match("/not connect/",$buffer)) {  
        echo "don`t connect\n";  
        break;  
    } else {  
        //服务器传来信息  
        echo "Buffer Data: " . $buffer . "\n";  
  
        echo "Writing to Socket\n";  
        // 将客户的信息写到通道中，传给服务器端  
        if (!socket_write($socket, "SOME DATA\n")) {  
            echo "Write failed\n";  
        }  
        //服务器端收到信息后，给于的回应信息  
        while ($buffer = socket_read($socket, 1024, PHP_NORMAL_READ)) {  
                echo "sent to server: SOME DATA\n response from server was:" . $buffer . "\n";  
        }         
  
    }  
}   */
  
?>  